﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MuMen
{
    [Serializable]
    class DingDan
    {
        public DingDan()
        {
            DingDanID = Guid.NewGuid().ToString();
            DingDanNo = "";
            CustomName = "";
            CustomTelephone = "";
            CustomAddress = "";
            DingDanColor = "";
            DingDanPi = "";
            DingDanComeDate = DateTime.Today;
            DingDanGoDate = DateTime.Today;
            BeiZhu = "";
            TaoBanCount = 0;
            TaoXianCount = 0;
            TaoXianMiSub = 0;
            TaoBanMiSub = 0;
            QianSub = 0;

            DingDanInstaller = "";
            DingDanProgress = "";
            TaoBanShuangCount = 0;
            TaoBanDanCount = 0;
            TiePiFeiStr = "";
        }

        /// <summary>
        /// 订单ID
        /// </summary>
        public string DingDanID { get; set; }
        /// <summary>
        /// 订单编号(带订货日期，自然编号，原始单号，地址缩写)
        /// </summary>
        public string DingDanNo { get; set; }
        /// <summary>
        /// 客户姓名
        /// </summary>
        public string CustomName { get; set; }

        /// <summary>
        /// 客户地址
        /// </summary>
        public string CustomAddress { get; set; }

        /// <summary>
        /// 客户电话
        /// </summary>
        public string CustomTelephone { get; set; }
        /// <summary>
        /// 颜色
        /// </summary>
        public string DingDanColor { get; set; }
        /// <summary>
        /// 门皮种类（纸皮还是木皮）
        /// </summary>
        public string DingDanPi { get; set; }
        /// <summary>
        /// 订货时间
        /// </summary>
        public DateTime DingDanComeDate { get; set; }
        /// <summary>
        /// 交货时间
        /// </summary>
        public DateTime DingDanGoDate { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string BeiZhu { get; set; }

        /// <summary>
        /// 套板个数
        /// </summary>
        public int TaoBanCount { get; set; }

        /// <summary>
        /// 套板双开个数
        /// </summary>
        public int TaoBanShuangCount { get; set; }

        /// <summary>
        /// 套板单开个数
        /// </summary>
        public int TaoBanDanCount { get; set; }

        /// <summary>
        /// 安装人
        /// </summary>
        public String DingDanInstaller { get; set; }

        /// <summary>
        /// 进度(下订单，刮腻子，贴皮，底漆，面漆，打包，已安装，已结账)
        /// </summary>
        public String DingDanProgress { get; set; }

        /// <summary>
        /// 套线计算
        /// </summary>
        public String TaoXianSuan { get; set; }

        /// <summary>
        /// 贴皮工费
        /// </summary>
        public int TiePiFei { get; set; }
        /// <summary>
        /// 贴皮工费
        /// </summary>
        public String TiePiFeiStr { get; set; }

        /// <summary>
        /// 油工工费
        /// </summary>
        public int PenQiFei { get; set; }
        /// <summary>
        /// 油工工费
        /// </summary>
        public String PenQiFeiStr { get; set; }

        /// <summary>
        /// 安门工费
        /// </summary>
        public int AnMenFei { get; set; }

        /// <summary>
        /// 套线个数
        /// </summary>
        public int TaoXianCount { get; set; }

        /// <summary>
        /// 门个数
        /// </summary>
        public int MenCount { get; set; }

        /// <summary>
        /// 套线总米数
        /// </summary>
        public float TaoXianMiSub { get; set; }

        /// <summary>
        /// 套板总米数
        /// </summary>
        public float TaoBanMiSub { get; set; }

        /// <summary>
        /// 总钱数
        /// </summary>
        public double QianSub { get; set; }

        /// <summary>
        /// 读取订单
        /// </summary>
        /// <returns></returns>
        public static List<DingDan> GetChooser()
        {

            List<DingDan> chooser = new List<DingDan>();

            string path = string.Format("{0}\\DingDan.bin", System.Windows.Forms.Application.StartupPath);

            if (!File.Exists(path))
            {
                return null;
            }

            //Chooser chooser = new Chooser();
            Encrypt_Decrypt ed = new Encrypt_Decrypt(path);
            chooser = (List<DingDan>)ed.DeSerialize();
            return chooser;
        }

        /// <summary>
        /// 写入订单
        /// </summary>
        /// <param name="chooser">订单列表</param>
        /// <returns></returns>
        public static bool SetChooser(List<DingDan> chooser)
        {
            string path = string.Format("{0}\\DingDan.bin", System.Windows.Forms.Application.StartupPath);

            if (!File.Exists(path))
            {
                return false;
            }

            Encrypt_Decrypt ed = new Encrypt_Decrypt(path);
            ed.Serialize(chooser);
            return true;
        }
    }
}
